#include "zutilinc.h"

#if  ZUTIL_OSTYPE==ZUTIL_ANDROID

#include "zluaobj.h"
extern "C" {
	#include "luasocket.h"
	int luaopen_lpeg (lua_State *L);
	int luaopen_luasql_sqlite3(lua_State *L);
	int luaopen_zpack(lua_State *L);
    int luaopen_bit(lua_State *L);
}
ZLuaEnvDelegateAndroid::ZLuaEnvDelegateAndroid()
{
}
const zString& ZLuaEnvDelegateAndroid::GetPath(ZLuaEnv::EPATH p)
{
	static zString s_path="";
	if (p<ZLuaEnv::ZPATH_DEFAULT || p >=ZLuaEnv::ZPATH_MAXNUM)
		p=ZLuaEnv::ZPATH_DEFAULT;
	return s_path;
}

int ZLuaEnvDelegateAndroid::OnCreateLuaEnv(ZLuaEnv& le)
{
	ZLuaEnvDelegate::OnCreateLuaEnv(le);
	zString rp="package.path='"+m_path[ZLuaEnv::ZPATH_MOD]+"lua/?.lua;"+m_path[ZLuaEnv::ZPATH_MOD]+"lualib/?.lua;'..package.path\npackage.cpath=''";
	le.dostring(rp);
	luaopen_zpack(le);
	le.dostring("package.loaded['zpack']={zpack=zpack,zunpack=zunpack}");
	luaopen_lpeg(le);
	luaopen_luasql_sqlite3(le);
	le.dostring("package.loaded['luasql.sqlite3']=luasql");
	luaopen_socket_core(le);
	le.dostring("package.loaded['socket.core']=socket; package.loaded['socket']=nil");
    luaopen_bit(le);
	return 0;
}
#endif
